package com.dongbo.recorder.screenrecord.ui.activity;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.TextView;

import com.gyf.immersionbar.ImmersionBar;
import com.dongbo.recorder.screenrecord.AppLpds;
import com.dongbo.recorder.screenrecord.R;
import com.dongbo.recorder.screenrecord.base.BaseActivity;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * description：
 * author：lutengxuan
 * CreateDate：2021-06-23
 */
public class CustomerServiceActivity extends BaseActivity {

    @BindView(R.id.tv_qq1)
    TextView tvQq1;
    @BindView(R.id.tv_qq2)
    TextView tvQq2;
    @BindView(R.id.tv_ems)
    TextView tvEms;


    @Override
    protected int getLayout() {
        return R.layout.activity_customer_service;
    }

    @Override
    protected void initView() {
        ImmersionBar.with(this)
                .fitsSystemWindows(true)
                .statusBarColor(R.color.white)
                .statusBarDarkFont(true)
                .init();
        if (AppLpds.getInstance().getmQq() != null) {
            tvQq1.setText(AppLpds.getInstance().getmQq().getQq1());
            tvQq2.setText(AppLpds.getInstance().getmQq().getQq2());
            tvEms.setText(AppLpds.getInstance().getmQq().getEmail());
        }
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initListener() {

    }

    @OnClick({R.id.btnLeft,
            R.id.iv_consult1,
            R.id.iv_consult2,
            R.id.btn_copy})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btnLeft:
                finish();
                break;
            case R.id.iv_consult1:
                openQQ(tvQq1.getText().toString().trim());
                break;
            case R.id.iv_consult2:
                openQQ(tvQq2.getText().toString().trim());
                break;
            case R.id.btn_copy:
                onCopy();
                break;
        }
    }

    private void onCopy() {
        try {
            //获取剪贴板管理器：
            ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
            // 创建普通字符型ClipData
            ClipData mClipData = ClipData.newPlainText("zkhc_gzk", tvEms.getText().toString().trim());
            // 将ClipData内容放到系统剪贴板里。
            cm.setPrimaryClip(mClipData);
            showToast("复制完成");
        } catch (Exception e) {
            showToast("复制失败请重试~");
        }
    }

    private void openQQ(String qq) {
        try {
            String url = "mqqwpa://im/chat?chat_type=wpa&uin=" + qq;
            //uin是发送过去的qq号码
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
        } catch (Exception e) {
            e.printStackTrace();
            showToast("您还没有安装QQ，请先安装软件");
        }
    }

}
